﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//Gọi Service library
using Googlempas_Form.ServiceReference;
using System.Data.SqlClient;
using System.Data.SqlTypes;

namespace Googlempas_Form
{
    public partial class App_form_webservice : Form
    {
        ServiceClient SerClient = new ServiceClient();
        
        Database_CN csdl = new Database_CN();
        private static string ID;
        //Đưa dữ liệu vào Combox
        public void DulieuLinhvuc()
        {
            string str = @"Select ID,Phanloai From PL ";
            comboBox1.DataSource = csdl.TaoBang(str);
            comboBox1.DisplayMember = "Phanloai";
            comboBox1.ValueMember = "ID";
            ID = comboBox1.SelectedValue.ToString();
           // comboBox1.Show();
        }

        public App_form_webservice()
        {
            InitializeComponent();
        }

        private void App_form_webservice_Load(object sender, EventArgs e)
        {
            DulieuLinhvuc();
            DulieuPhanloai("1",comboBox3);         
        }

        public void DulieuPhanloai(string str,ComboBox cbbox)
        {
            
                string sql = @"Select ID,Phanloai From dbo.PL Where ID_LV='"+str+"'";
                cbbox.DataSource = csdl.TaoBang(sql);
                cbbox.DisplayMember = "Phanloai";
                cbbox.ValueMember = "ID";
                cbbox.Show();         
           
           

        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //ID = comboBox1.SelectedValue.ToString();
            textBox1.Text = "2";
            //DulieuPhanloai(textBox1.Text,comboBox3);
            //string sql = @"Select ID,Phanloai From dbo.PL";
            //Database_CN.ThietlapKetnoi();
            //SqlDataAdapter adapter = new SqlDataAdapter(sql,Database_CN.CN);
            //DataTable datatable = new DataTable();
            //adapter.Fill(datatable);
            //comboBox2.DataSource = datatable;
            //comboBox2.Show();
            //Database_CN.HuyKetnoi();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(textBox2.Text);
            dataGridView1.DataSource = SerClient.Xemkhachsan(id);
            dataGridView1.Show();
        }
        public DataTable Xemkhachsan1(int Malinhvuc)
        {
            DataTable DTable = new DataTable();
            switch (Malinhvuc)
            {
                case 1:
                    {
                        Database_CN.ThietlapKetnoi();
                        SqlDataAdapter Adapter = new SqlDataAdapter("Select* From KS", Database_CN.CN);
                        Adapter.Fill(DTable);
                        Adapter.Update(DTable);
                        return DTable;
                    } break;
                case 2:
                    {
                        Database_CN.ThietlapKetnoi();
                        SqlDataAdapter Adapter = new SqlDataAdapter("Select* From MSam", Database_CN.CN);
                        Adapter.Fill(DTable);
                        Adapter.Update(DTable);
                        return DTable;
                    } break;
                case 3:
                    {
                        Database_CN.ThietlapKetnoi();
                        SqlDataAdapter Adapter = new SqlDataAdapter("Select* From GTri", Database_CN.CN);
                        Adapter.Fill(DTable);
                        Adapter.Update(DTable);
                        return DTable;
                    } break;
                case 4:
                    {
                        Database_CN.ThietlapKetnoi();
                        SqlDataAdapter Adapter = new SqlDataAdapter("Select* From AThuc", Database_CN.CN);
                        Adapter.Fill(DTable);
                        Adapter.Update(DTable);
                        return DTable;
                    } break;
                case 5:
                    {
                        Database_CN.ThietlapKetnoi();
                        SqlDataAdapter Adapter = new SqlDataAdapter("Select* From LDep", Database_CN.CN);
                        Adapter.Fill(DTable);
                        Adapter.Update(DTable);
                        return DTable;
                    } break;
                case 6:
                    {
                        Database_CN.ThietlapKetnoi();
                        SqlDataAdapter Adapter = new SqlDataAdapter("Select* From DLich", Database_CN.CN);
                        Adapter.Fill(DTable);
                        Adapter.Update(DTable);
                        return DTable;
                    } break;
                case 7:
                    {
                        Database_CN.ThietlapKetnoi();
                        SqlDataAdapter Adapter = new SqlDataAdapter("Select* From YTe", Database_CN.CN);
                        Adapter.Fill(DTable);
                        Adapter.Update(DTable);
                        return DTable;
                    } break;
                case 8:
                    {
                        Database_CN.ThietlapKetnoi();
                        SqlDataAdapter Adapter = new SqlDataAdapter("Select* From TChinh", Database_CN.CN);
                        Adapter.Fill(DTable);
                        Adapter.Update(DTable);
                        return DTable;

                    } break;
                default:
                    {
                        Database_CN.ThietlapKetnoi();
                        SqlDataAdapter Adapter = new SqlDataAdapter("Select* From GDuc", Database_CN.CN);
                        Adapter.Fill(DTable);
                        Adapter.Update(DTable);
                        return DTable;
                    } break;


            }
        }              
    }
}
